<!DOCTYPE html >
<html>
<head>
<meta name="Generator" content="TPshop v1.1" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>话术管理</title>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
<!-- <link rel="stylesheet" href="__ROOT__ /AI_radar/css/footer.css"> -->
<link rel="stylesheet" href="__ROOT__ /AI_radar/css/font_my/iconfont.css">
<script type="text/javascript" src="__ROOT__ /AI_radar/js/token.js"></script>
<style type="text/css">
	body,html{
		width: 100%;
		height: 100%;
		margin: 0;
		padding: 0;
		overflow-x: hidden;
		color:#555555;
		background: #fff;
	}
	p{
		margin: 0;
		line-height: 50px;
	}
	.trick{
		width: calc(100% - 20px);
		height: 100%;
		padding: 0 10px;
		display: flex;
	}
	.trickL{
		width: 100px;
		height: 100%;
		border-right: 1px solid #ccc;
		text-align: center;
	}
	.trickR{
		width: calc(100% - 102px);
		height: 100%;
		padding-left: 10px;
		font-size: 14px;
	}
	.trickPs{
		background: #4f81d4;
		color:#fff;
	}
	.trickdiv{
		height: 50px;
	}
	.trickFont{
		width: 80px;
		line-height: 30px;
		margin:10px 10px 10px 0;
	}
	.trickse{
		background: #4f81d4;
		color: #fff;
	}
	.trickRjia{
		width: 100%;
		line-height: 35px;
		color: #4f81d4;
		text-indent: 10px;
	}
	
	.trickOne{
		margin: 10px 0;
		border:1px solid #f6b37f;
		border-radius: 3px;
		padding:5px;
	}
	.trickOneTitle,.trickOneContent{
		line-height: 30px;
	}
	.trickCz{
		width: 100%;
		height: 30px;
		/*display: flex;*/
		/*text-align: right;*/
		position: relative;
		color: #428bca;
	}
	.trickUpdate{
		width: 40px;
		float: right;
		line-height: 30px;
		/*position: absolute;*/
		/*top: 0;*/
		/*right:45px;*/
	}
	.trickDel{
		width: 40px;
		float: right;
		line-height: 30px;
		/*position: absolute;*/
		/*top: 0;*/
		/*right:0;*/
	}
	




</style>

</head>
<body onload = "aa()">
	{include file="public/wx_share" /}
	<div class="trick">
		<div class="trickL">
			<!-- <div class="trickdiv trickdiv1"><div class="trickFont trickse" did='1'>最近使用</div></div>
			<div class="trickdiv trickdiv2"><div class="trickFont" did='2'>提问</div></div>
			<div class="trickdiv trickdiv3"><div class="trickFont" did='3'>欢迎</div></div> -->
			<!-- <div class="trickadds"></div> -->
			<div class="trickdiv trickdivs"><div class="trickFont zdy" did='0'>自定义</div></div>

		</div>
		<div class="trickR"></div>

	</div>

<script src='__ROOT__ /AI_radar/js/jquery.js'></script>
<script type="text/javascript">
	var test = window.location.href;
    var jin1 = test.indexOf('?id=');
    
    
    // var jin3 = jin1 + 4;
    // var jin = test.slice(jin3);
    console.log(jin1)
	function aa(){
	    if(window.name=="cur"){
	    	console.log(4444)
	    }else{
	      window.name="cur";
	      console.log(5555)
	    }
	}

	window.onpageshow=function(e){
	    var a=e||window.event;

		console.log(a.persisted)
	   
	//     if(a.persisted){

	//         window.location.href= window.location.href;
	//     }
	}

	console.log(11111)
	//查询话术类
	trickClassAjax(jin1)
    function trickClassAjax(jin1){
        $.ajax({
            url:window.urls.url + "/my/trick/category",
            type:"POST",
            contentType: "application/json",
            dataType:"json",
            data:JSON.stringify({
                token:window.tokens.token_boss
            }),
            success:function(res){
            	var nums;
                if(res.data){
	                res.data.forEach(function(el,index){
	                	var div
	                	if(index == 0){
	                		nums = el.id
	                		div = "<div class='trickdiv trickdiv2'><div class='trickFont trickse' did='"+el.id+"'>"+el.name+"</div></div>"
	                	}else{
	                	    div = "<div class='trickdiv trickdiv2'><div class='trickFont' did='"+el.id+"'>"+el.name+"</div></div>"
	                	}
	                	$(".trickdivs").before(div);
	                })
                }else{
                	document.querySelector(".zdy").classList.add("trickse")
                }
                var trickFont = document.querySelectorAll(".trickFont")
                trickClick(trickFont)
                if(nums){
                	trickAllAjax(nums)
                }
               
            },
            error:function(res){
              console.log(res)
              alert("请求数据失败")
            }
        })
    }

    //查看话术
     function trickAllAjax(num){
     	console.log(jin1)
        $.ajax({
            url:window.urls.url + "/my/trick/category/list",
            type:"POST",
            contentType: "application/json",
            dataType:"json",
            data:JSON.stringify({
                token:window.tokens.token_boss,
                categoryId:num
            }),
            success:function(res){
                console.log(res.data)
                if(res.data){
	                res.data.forEach(function(el,ind){
	                	var div
		                if(num != 0){
		                
		                	div = $("<div class='trickOne'><div class='trickOneTitle'>关键词："+el.keyword+"</div><div class='trickOneContent'>话术内容："+el.content+"</div></div>")
		                	$(div).appendTo(".trickR")
		                }
	                })
                }else{
                	var div =  $("<div class='trickOne'>暂无话术</div>")
                	$(div).appendTo(".trickR")
                }
                if(jin1 != -1){
			    	var trickFonts = document.querySelectorAll(".trickFont")
			    	Array.from(trickFonts).forEach(function(a,b){
					    a.classList.remove("trickse")
				    })
			    	$(".trickR").children().each(function(ind,dom){
			    		dom.remove()
			    	})
				    document.querySelector(".zdy").classList.add("trickse")
			    	var jia = $("<div class='trickRjia'><i class='iconfont icon-jiahao'></i> 添加话术</div>")
					$(jia).appendTo(".trickR")
					$(".trickRjia").click(function(){
						addHUa(0)
					})
					trickMyAjax()
			    }
            },
            error:function(res){
              console.log(res)
              alert("请求数据失败")
            }
        })
    }
    //查看自定义话术
     function trickMyAjax(){
        $.ajax({
            url:window.urls.url + "/my/trick/list",
            type:"POST",
            contentType: "application/json",
            dataType:"json",
            data:JSON.stringify({
                token:window.tokens.token_boss,
            }),
            success:function(res){
                if(res.data){
	                res.data.forEach(function(el,ind){
	               		var div = "<div class='trickOne'><div class='trickOneTitle'>关键词："+el.keyword+"</div><div class='trickOneContent'>话术内容："+el.content+"</div><div class='trickCz'><div class='trickUpdate' sid='"+el.id+"'>编辑</div><div class='trickDel' sid='"+el.id+"'>删除</div></div></div>"
	                	$(".trickRjia").before(div)
	                })
	                var dels = document.querySelectorAll('.trickDel')
	                del(dels)
	                var trickUpdate = document.querySelectorAll('.trickUpdate')
	                update(trickUpdate)
                }
            },
            error:function(res){
              console.log(res)
              alert("请求数据失败")
            }
        })
    }
    //删除话术
     function deletes(nums,dom){
     	console.log(nums)
        $.ajax({
            url:window.urls.url + "/my/trick/delete",
            type:"POST",
            contentType: "application/json",
            dataType:"json",
            data:JSON.stringify({
                token:window.tokens.token_boss,
                id:nums
            }),
            success:function(res){
            	console.log(res)
            	
            	if(res.data == 1){
            		alert("删除成功")
            		dom.remove()
            	}else{
            		aiert("删除失败，请刷新页面重试")
            	}
               
            },
            error:function(res){
              console.log(res)
              // alert("请求数据失败")
            }
        })
    }
	// var trickFont = document.querySelectorAll(".trickFont")
	//点击话术分类查询
	function trickClick(trickFont){
	    Array.from(trickFont).forEach(function(c,d){
	      c.onclick = function(){
	      	Array.from(trickFont).forEach(function(a,b){
			    a.classList.remove("trickse")
		    })
		    $(".trickR").children().each(function(ind,dom){
	    		dom.remove()
	    	})
		    c.classList.add("trickse")
		    if(c.getAttribute("did") == 0){
		    	var jia = $("<div class='trickRjia'><i class='iconfont icon-jiahao'></i> 添加话术</div>")
				$(jia).appendTo(".trickR")
				$(".trickRjia").click(function(){
					addHUa(0)
				})
				trickMyAjax()
		    }else{
		    	trickAllAjax(c.getAttribute("did"))
		    }
		    
	      }
	    })
		
	}
	//跳页
    function addHUa(num){
    	console.log(11111111)
    	window.location.href=window.urls.url + `/my/trickAdd?id=${num}&corpid=${localStorage.getItem("CRM_corpId")}`
    }
    //删除自定义方法
    function del(arr){
    	Array.from(arr).forEach(function(dom,index){
    		dom.onclick = function(){
    			console.log(dom.getAttribute("sid"))
    			if(confirm("确定删除话术？")){
    				deletes(dom.getAttribute("sid"),dom.parentNode.parentNode)
    				// dom.parentNode.parentNode.remove()
    			}
    		}
    	})
    }
    //编辑自定义方法
    function update(arr){
    	Array.from(arr).forEach(function(dom,index){
    		dom.onclick = function(){
    			console.log(dom.getAttribute("sid"))
    			addHUa(dom.getAttribute("sid"))
    		}
    	})
    }
</script>
</body>
</html>